<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>父组件向子组件动态传值示例</title>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>

</head>

<body>
    <div id="app">
        <p>添加一个列表项：
            <input type="text" v-model="newItem" v-on:keyup.enter='addNew()' placeholder="按回车键提交">
        </p>
      <component-a :m='msgchildtofather'></component-a>
    
    
    </div>
</body>

<script>
    Vue.component('component-a', {
        props: ['m'],
        template: '<h2 v-text=\'m\'></h2>',
        
    })

    new Vue({
        el: "#app",
        data: {
            items: [],
            newItem: "",
            msgchildtofather: ""
            
        },
        methods: {
            addNew: function () {
                // 使用v-model和ul li input向数组items添加一个动态项内容，注意添加数组格式
                this.items.push(this.newItem);
                // 测试传递动态添加对象值
                var childfather = {
                    label: this.newItem,
                  
                };
                this.msgchildtofather = childfather.label;

                this.newItem = "";
            }
        },
    })
</script>

</html>